package com.ruibei.ui.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

import com.ruibei.R;
import com.ruibei.ui.adapter.TimelineAdapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

/**
 * 审批的进度页面
 *
 * @author limingyan
 *
 */
public class ApprovalProgressFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
	
	@InjectView (R.id.progress_listview)
	ListView mListView;
	@InjectView (R.id.swipe_container)
	SwipeRefreshLayout mSwipeRefreshLayout;
	
	private View mBaseView;
	List<String> mData ;
	private TimelineAdapter mTimelineAdapter;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mBaseView = inflater.inflate(R.layout.fragment_approval_progress, container,
				false);
		ButterKnife.inject(this, mBaseView);
		initView();
		
		return mBaseView;
	}
	
	private void initView(){
		mListView.setDividerHeight(0);
		mTimelineAdapter = new TimelineAdapter(getActivity(), getData());
		mListView.setAdapter(mTimelineAdapter);
		
		mSwipeRefreshLayout.setOnRefreshListener(this);
		mSwipeRefreshLayout.setColorSchemeResources(R.color.blue); 
	}
	
	private List<Map<String, Object>> getData() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("title", "这是第1行测试数据");
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("title", "这是第2行测试数据");
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("title", "这是第3行测试数据");
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("title", "这是第4行测试数据");
		list.add(map);
		return list;
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				mSwipeRefreshLayout.setRefreshing(false);
			}
		}, 5000);
	}
}
